import { _decorator, Component, Label, Node, Sprite, UITransform, v3 } from 'cc';
import { BasePanel } from './BasePanel';
import { PropItem } from '../items/props/PropItem';
import { BaseProp } from '../props/BaseProp';
import { _resource } from '../Main';
import { Adsdk } from '../scenes/Adsdk';
const { ccclass, property } = _decorator;

@ccclass('PropPanel')
export class PropPanel extends BasePanel {
    
    panelName: string = '道具'

    @property(Label)
    propName: Label = null!

    @property(Sprite)
    propIcon: Sprite = null!

    @property(Label)
    propDesc: Label = null!

    @property(Label)
    coin: Label = null!

    prop: PropItem = null

    baseProp: BaseProp = null

    init(prop: PropItem, baseProp: BaseProp = null) {
        this.prop = prop
        this.propName.string = this.prop.showName
        this.propDesc.string = this.prop.shortDesc
        this.coin.string = this.prop.cost + ''

        this.propIcon.spriteFrame = this.prop.icon
        _resource.spriteFitSquare(this.propIcon, 80, 80)

        this.baseProp = baseProp
    }

    buy() {
        this.prop.buy(1, () => {
            if (this.baseProp == null) {
                return
            }
            this.baseProp.refreshCount()
        })
    }

    video() {
        this.close(() => {
            this.prop.videoThenUse(() => {
                if (this.baseProp == null) {
                    return
                }
                this.baseProp.refreshCount()
            })
        })
    }
}


